package sn.gandal.agriculture.agrimobile.j2me.dao;

import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreNotFoundException;
import javax.microedition.rms.RecordStoreNotOpenException;

/**
 *
 * @author suyash
 */
public class UtilitiesDAO
{

    public static boolean recordStoreExist(String tableName) throws RecordStoreException
    {
	boolean ret = false;
	RecordStore rs = RecordStore.openRecordStore(tableName, true);

	if (rs.getNumRecords() > 0)
	{
	    ret = true;
	}
	else
	{
	    ret = false;
	}

	rs.closeRecordStore();

	return ret;
    }

    public static boolean openStore(String name, boolean createIfNotExist) throws RecordStoreNotOpenException, RecordStoreException{
        RecordStore rs = null;
        boolean open=true;
       
        try {
            rs = RecordStore.openRecordStore(name, createIfNotExist);
        } catch (RecordStoreException ex) {
            ex.printStackTrace();
            open=false;
        }finally {
            if(rs!=null)
                rs.closeRecordStore();            
            open=false;
        }
        return open;
    }
}
